﻿using System.Collections.Generic;
using HK.Core.Common.Data;
using HK.Core.Common.Protocol.Data;
using HK.Core.Serializable.Data;
using HK.Core.Serializable.Protocol.Data;
using HK.Editor.Settings.Data;

namespace HK.Editor.Settings.Protocol.Data
{

#if PREFAB_SPLIT
    
    /// <summary>
    /// 接口 : 预制体信息
    /// </summary>
    public interface IPrefabInfo : IListElement 
    {
        /// <summary>
        /// 拆分对象
        /// </summary>
        string AssetKey { get; }
    }

    /// <summary>
    /// 接口 : 分割预制体信息
    /// </summary>
    /// <typeparam name="TResult">拆分预制体类型</typeparam>
    public interface IPrefabSplit<TResult> : IPrefabInfo where TResult : JsonData, IPrefabInfo
    {
        /// <summary>
        /// 拆分深度
        /// </summary>
        int Depth { get; }
        
        /// <summary>
        /// 节点白名单
        /// </summary>
        IWhiteList WhiteList { get; }

        /// <summary>
        /// 判断节点名是否包含在节点白名单中
        /// </summary>
        /// <param name="iNodeName">节点名</param>
        /// <returns>true:包含;false:不包含;</returns>
        bool ContainInWhiteList(string iNodeName);
        
        /// <summary>
        /// 拆分结果列表
        /// </summary>
        List<string> Result { get; }
        
        /// <summary>
        /// 保存拆分结果
        /// </summary>
        /// <param name="iResult">拆分结果列表</param>
        /// <returns>true:成功; false:失败;</returns>
        bool SaveResult(List<string> iResult);
    }

    /// <summary>
    /// 接口 : 预制体分页列表
    /// </summary>
    /// <typeparam name="TList">列表类型</typeparam>
    /// <typeparam name="TPrefab">预制体信息类型</typeparam>
    public interface IPrefabsPagination<TList, TPrefab> : IListJsonData<TPrefab>
        where TList : JsonData, IListJsonData<TPrefab>
        where TPrefab : JsonData, IPrefabInfo
    {
    }

    /// <summary>
    /// 接口 : 预制体拆分分页列表
    /// </summary>
    /// <typeparam name="TList">列表类型</typeparam>
    /// <typeparam name="TSplit">预制体拆分类型</typeparam>
    /// <typeparam name="TPrefab">预制体信息类型</typeparam>
    public interface IPrefabsSplitPagination<TList, TSplit, TPrefab> : IPrefabsPagination<TList, TSplit>
        where TList : JsonData, IListJsonData<TSplit>
        where TSplit : JsonData, IPrefabSplit<TPrefab>
        where TPrefab : JsonData, IPrefabInfo
    {
        /// <summary>
        /// 保存拆分结果
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iResult">拆分结果列表</param>
        /// <returns>true:成功; false:失败;</returns>
        bool SaveResult(string iAssetKey, List<string> iResult);
    }

    /// <summary>
    /// 接口 : 预制体配置
    /// </summary>
    public interface IPrefabConf : IJsonData
    {

#region Split

        /// <summary>
        /// 拆分标志位
        /// </summary>
        bool Split { get; }
        
        /// <summary>
        /// 预制体拆分列表
        /// </summary>
        IPrefabsSplitPagination<PrefabsSplitPagination, PrefabSplit, PrefabInfo> SplitList { get; }
        
        /// <summary>
        /// 拆分标志位
        /// </summary>
        bool PrefabSplit { get; }

        /// <summary>
        /// 判断预制体是否为需要拆分的预制体
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <returns>true:是; false:否;</returns>
        bool IsSplitPrefab(string iAssetKey);

        /// <summary>
        /// 取得分割列表
        /// </summary>
        /// <param name="iAssetKey"></param>
        /// <returns></returns>
        List<string> GetSplitResult(string iAssetKey);

        /// <summary>
        /// 保存拆分结果
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iResult">拆分结果列表</param>
        /// <returns>true:成功; false:失败;</returns>
        bool SaveSplitResult(string iAssetKey, List<string> iResult);

#endregion

    }
    
#endif
    
    /// <summary>
    /// 接口 : 打包配置信息数据
    /// </summary>
    public interface IBuildConfData : ISAssetData
    {

        /// <summary>
        /// 本地输出目录
        /// </summary>
        string OutputDir { get; }

#if PREFAB_SPLIT

#region Prefab

        /// <summary>
        /// 预制体设定
        /// </summary>
        IPrefabConf PrefabConf { get; }
        
        /// <summary>
        /// 拆分标志位
        /// </summary>
        bool PrefabSplit { get; }
        
        /// <summary>
        /// 判断预制体是否为需要拆分的预制体
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <returns>true:是; false:否;</returns>
        bool IsSplitPrefab(string iAssetKey);

        /// <summary>
        /// 取得分割列表
        /// </summary>
        /// <param name="iAssetKey"></param>
        /// <returns></returns>
        List<string> GetSplitResult(string iAssetKey);

        /// <summary>
        /// 保存拆分结果
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iResult">拆分结果列表</param>
        /// <returns>true:成功; false:失败;</returns>
        bool SaveSplitResult(string iAssetKey, List<string> iResult);

#endregion
        
#endif

#region App

        /// <summary>
        /// App打包配置
        /// </summary>
        IBuildAppConf AppConf { get; }

        /// <summary>
        /// App版本
        /// </summary>
        ISAssetVersion AppVersion { get; }

        /// <summary>
        /// 重置App版本
        /// </summary>
        /// <param name="iVersion">App版本</param>
        /// <returns>true:有变化; false:无变化;</returns>
        bool ResetAppVersion(string iVersion);

#endregion
        
#region Resource

        /// <summary>
        /// 资源打包配置
        /// </summary>
        IBuildResourceConf ResourceConf { get; }

        /// <summary>
        /// 母包版本
        /// </summary>
        ISAssetVersion OriginVersion { get; }

        /// <summary>
        /// 重置母包版本
        /// </summary>
        /// <param name="iVersion">母包版本</param>
        /// <returns>true:有变化; false:无变化;</returns>
        bool ResetOriginVersion(string iVersion);

        /// <summary>
        /// 上一母包版本
        /// </summary>
        ISAssetVersion LastOriginVersion { get; }
        
        /// <summary>
        /// 重置上一次母包版本
        /// </summary>
        /// <param name="iVersion">母包版本</param>
        /// <returns>true:有变化; false:无变化;</returns>
        bool ResetLastOriginVersion(string iVersion);

        /// <summary>
        /// 补丁版本
        /// </summary>
        ISAssetVersion PatchVersion { get; }
        
        /// <summary>
        /// 重置补丁版本
        /// </summary>
        /// <param name="iVersion">母包版本</param>
        /// <returns>true:有变化; false:无变化;</returns>
        bool ResetPatchVersion(string iVersion);

        /// <summary>
        /// 上一补丁版本
        /// </summary>
        ISAssetVersion LastPatchVersion { get; }
        
        /// <summary>
        /// 重置上一次母包版本
        /// </summary>
        /// <param name="iVersion">母包版本</param>
        /// <returns>true:有变化; false:无变化;</returns>
        bool ResetLastPatchVersion(string iVersion);

#endregion
        
    }
    
    /// <summary>
    /// 接口 : 打包配置
    /// </summary>
    /// <typeparam name="TData">打包配置类型</typeparam>
    public interface IBuildConf<out TData> : ISAsset<TData>
        where TData : SAssetData, new()
    {
        
        /// <summary>
        /// 本地输出目录
        /// </summary>
        string OutputDir { get; }
        
#region App

        /// <summary>
        /// App版本
        /// </summary>
        ISAssetVersion AppVersion { get; }

        /// <summary>
        /// 重置App版本
        /// </summary>
        /// <param name="iVersion">App版本</param>
        /// <returns>true:有变化; false:无变化;</returns>
        bool ResetAppVersion(string iVersion);

#endregion

#region Resource

        /// <summary>
        /// 母包版本
        /// </summary>
        ISAssetVersion OriginVersion { get; }

        /// <summary>
        /// 重置母包版本
        /// </summary>
        /// <param name="iVersion">母包版本</param>
        /// <returns>true:有变化; false:无变化;</returns>
        bool ResetOriginVersion(string iVersion);

        /// <summary>
        /// 上一母包版本
        /// </summary>
        ISAssetVersion LastOriginVersion { get; }
        
        /// <summary>
        /// 重置上一次母包版本
        /// </summary>
        /// <param name="iVersion">母包版本</param>
        /// <returns>true:有变化; false:无变化;</returns>
        bool ResetLastOriginVersion(string iVersion);

        /// <summary>
        /// 补丁版本
        /// </summary>
        ISAssetVersion PatchVersion { get; }
        
        /// <summary>
        /// 重置补丁版本
        /// </summary>
        /// <param name="iVersion">母包版本</param>
        /// <returns>true:有变化; false:无变化;</returns>
        bool ResetPatchVersion(string iVersion);

        /// <summary>
        /// 上一补丁版本
        /// </summary>
        ISAssetVersion LastPatchVersion { get; }
        
        /// <summary>
        /// 重置上一次母包版本
        /// </summary>
        /// <param name="iVersion">母包版本</param>
        /// <returns>true:有变化; false:无变化;</returns>
        bool ResetLastPatchVersion(string iVersion);

#endregion

    }
}
